package com.mingdinggroup.app.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import com.google.gson.stream.JsonReader;

import java.io.Reader;
import java.lang.reflect.Type;

/**
 * 作者：woodnaonly on 2017/2/7 17:01
 * 邮箱：497917264@qq.com
 * 内容：
 * 备注：
 */
public class GsonUtil {

    public static Gson getInstance() {
        return Holder.gson;
    }

    private static class Holder {
        public static final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create();
    }

    public static <T> T fromJson(String json, Class<T> type) throws JsonIOException, JsonSyntaxException {
        return getInstance().fromJson(json, type);
    }

    public static <T> T fromJson(String json, Type type) {
        return getInstance().fromJson(json, type);
    }

    public static <T> T fromJson(JsonReader reader, Type typeOfT) throws JsonIOException, JsonSyntaxException {
        return getInstance().fromJson(reader, typeOfT);
    }

    public static <T> T fromJson(Reader json, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
        return getInstance().fromJson(json, classOfT);
    }

    public static <T> T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException {
        return getInstance().fromJson(json, typeOfT);
    }

    public static String toJson(Object src) {
        return getInstance().toJson(src);
    }

    public static String toJson(Object src, Type typeOfSrc) {
        return getInstance().toJson(src, typeOfSrc);
    }
}
